﻿<body id="mainLayout" class="easyui-layout">
    <input id="hiddenId" type="hidden" />
    <div data-options="region:'center',border:false">
        <table id="dgRole" class="easyui-datagrid" rownumbers="true" fit="true" pagination="true" fitcolumns="false" striped="true" idfield="Id"
               url="GetRoleList?roleType=Sys" autorowheight="false" singleselect="false" toolbar="#tb" data-options="onClickRow:onClickRow">
            <thead>
                <tr>
                    <th data-options="field:'ck',checkbox:true"></th>
                    <th field="Code" width="150" halign='center'>
                        编号
                    </th>
                    <th field="Name" width="240" halign='center'>
                        名称
                    </th>
                </tr>
            </thead>
        </table>
    </div>
    <div data-options="region:'east',split:true,collapsible:false" style="width:500px;">
        <table id="dgFunc" class="easyui-treegrid" rownumbers="true" fit="true" pagination="false" fitcolumns="false" striped="true" border="false" idfield="Id" treefield="Text"
               url="GetFuncList" autorowheight="false" singleselect="true" data-options="onClickRow:onFuncClickRow,onEndEdit:onFuncEndEdit">
            <thead>
                <tr>
                    <th field="Text" width="240" halign='center'>
                        名称
                    </th>
                    <th field="Set" width="70" halign='center' formatter="trueFalseFormatter" align="center" editor="{type:'checkbox',options:{on:'true',off:'false'}}">
                        赋权
                    </th>
                </tr>
            </thead>
        </table>
    </div>
</body>
 <script>
     function trueFalseFormatter(value, rowData, rowIndex) {
         if (value == 'true') {
             return '是'
         }
         else {
             return '否'
         }
     }
 </script>
<script>

    function onClickRow(rowIndex, rowData)
    {
        $('#dgFunc').treegrid('load', { roleId: rowData.Id });

        //var queryParams = { roleId: rowData.Id };

        //$('#dg2').treegrid('options').queryParams = queryParams;
        //$("#dg2").treegrid('reload');
    }

    var currentRow;
    function onFuncClickRow(row) {
        //RoleFuncSave();
        if (currentRow != row) {
            if (currentRow != undefined) {
                $('#dgFunc').treegrid('endEdit', currentRow.Id);
            }

            $('#dgFunc').treegrid('beginEdit', row.Id);
            currentRow = row;
        }
    }
    function onFuncEndEdit(row)    {
        var selectedRole = $('#dgRole').treegrid('getSelected');
        if (!selectedRole) return msgBox('请选择角色');

        addAjaxParam("roleId", selectedRole.Id);
        addAjaxParam("row", row);
        commitAjax("UpdateRoleFunc", {
            CallBack: function (data) {
                if (data)
                {
                    $('#dgFunc').treegrid('reload');
                }
            }
        })
    }    function onValueChanged(e)    {
        msgBox(e);
    }
</script>

